package com.cyy.spring;

import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;

/**
 * @Author: Cyy
 * @Description: 测试类ProxyFactoryTest
 * @Date:Created in 19:42 2018/7/19
 */
public class ProxyFactoryTest {

    //没有指定代理类的使用cglib代理
    @Test
    public void classProxy(){
        ProxyFactory factory=new ProxyFactory();
        factory.setTarget(new MyTarget());
        factory.addAdvice(new AroundInteceptor());
        MyTarget myTarget = (MyTarget) factory.getProxy();
        myTarget.printName();
        System.out.println(myTarget.getClass().getName());
    }
    //指定代理类的使用jdk代理
    @Test
    public void interfaceProxy(){
        ProxyFactory factory=new ProxyFactory();
//        factory.setInterfaces(new Class[]{PeopleService.class});
        factory.addAdvice(new AroundInteceptor());
        factory.setTarget(new EnglishService());
        PeopleService peopleProxy = (PeopleService) factory.getProxy();
        peopleProxy.sayHello();
        peopleProxy.printName("cyy");
        System.out.println(peopleProxy.getClass().getName());
    }
}
